package pri.damai.xiaowu.usercenter.api.web;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;
import pri.damai.xiaowu.common.core.vo.QueryResultCommonVO;
import pri.damai.xiaowu.common.core.vo.ResultVO;
import pri.damai.xiaowu.common.log.anno.XiaoWuLog;
import pri.damai.xiaowu.usercenter.sysauth.entity.System;
import pri.damai.xiaowu.usercenter.sysauth.service.SystemService;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

import static pri.damai.xiaowu.common.core.vo.ResultVO.success;

/**
 * 后台系统信息(System)表控制层
 * @Desc
 * @Author DaMai
 * @Date 2022-03-03 17:54:04
 */
@XiaoWuLog
@RestController
@RequestMapping("system")
public class SystemController {
    /**
     * 服务对象
     */
    @Resource
    private SystemService systemService;

    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param system 查询实体
     * @return 所有数据
     */
    @GetMapping
    public ResultVO<QueryResultCommonVO<System>> selectAll(Page<System> page, System system) {
        Page<System> systemPage = this.systemService.page(page, new QueryWrapper<>(system));
        QueryResultCommonVO<System> queryResultCommonVO = QueryResultCommonVO.buildByIPage(systemPage);
        return success(queryResultCommonVO);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResultVO<System> selectOne(@PathVariable Serializable id) {
        return success(this.systemService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param system 实体对象
     * @return 新增结果
     */
    @PostMapping
    public ResultVO<Boolean> insert(@RequestBody System system) {
        return success(this.systemService.save(system));
    }

    /**
     * 修改数据
     *
     * @param system 实体对象
     * @return 修改结果
     */
    @PutMapping
    public ResultVO<Boolean> update(@RequestBody System system) {
        return success(this.systemService.updateById(system));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public ResultVO<Boolean> delete(@RequestParam("idList") List<Long> idList) {
        return success(this.systemService.removeByIds(idList));
    }
}
